/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package isas;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author Kubik
 */
public class AverageCalc {
    private String[] predmety;
    private int[] znamky;
    private int[] vahy;
    private float[] uniqPrumery;
    private int[] uniqVahy;
    private int[] uniqZnamky;
    private String[] uniqPredmety;
    
    public AverageCalc(String[] predmety, int[] znamky, int[] vahy){
        this.predmety = predmety;
        this.znamky = znamky;
        this.vahy = vahy;
        this.getUniqueSubjects();
        this.uniqZnamky = new int[uniqPredmety.length];
        this.uniqVahy = new int[uniqPredmety.length];
        this.getAverage();
        PrintGrades.print(uniqPredmety, uniqPrumery);
    }
    
    private void getUniqueSubjects(){
        List<String> lst = Arrays.asList(this.predmety);
        Set<String> set = new HashSet<>(lst);
        this.uniqPredmety = set.toArray(new String[set.size()]);
        boolean pause = true;
    }
    
    private void getAverage(){
        for(int i = 0; i < znamky.length; i++){
            String predmet;
            int znamka;
            int vaha;
            predmet = predmety[i];
            //if(predmet.equalsIgnoreCase("cjl")){
                znamka = znamky[i];
                vaha = vahy[i];
                int pozice = Arrays.asList(uniqPredmety).indexOf(predmet);
                uniqZnamky[pozice] = uniqZnamky[pozice]+(znamka*vaha);
                uniqVahy[pozice] = uniqVahy[pozice] + vaha;
            //}
        }
        this.uniqPrumery = new float[uniqZnamky.length];
        for(int i = 0; i < uniqZnamky.length; i++){
            this.uniqPrumery[i] = (float)uniqZnamky[i]/(float)uniqVahy[i];
        }
        boolean pause = true;
    }
}
